package com.koron.css2.newProjectCenter.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.newProjectCenter.bean.PjMeterMaterialBean;
import com.koron.css2.newProjectCenter.bean.query.PjMeterMaterialQueryBean;
import com.koron.css2.newProjectCenter.mapper.PjMeterMaterialMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import org.apache.commons.lang3.StringUtils;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.List;

/**
 * 工程施工勘察节点施工材料列表查询
 */
public class PjMeterMaterialList implements ServerInterface {

    @Override
    public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
        try {
            PjMeterMaterialQueryBean query = JsonUtils.objectToPojo(req.getData(), PjMeterMaterialQueryBean.class);
            if (StringUtils.isBlank(query.getPjId())){
                return MessageBean.create(Constant.MESSAGE_INT_FAIL,"pjId 不能为空",null);
            }
            PjMeterMaterialMapper pjMeterMaterialMapper = factory.getMapper(PjMeterMaterialMapper.class);
            List<PjMeterMaterialBean> pjMeterMaterialList = pjMeterMaterialMapper.selectByPjId(query.getPjId());
            MessageBean message = MessageBean.create(Constant.MESSAGE_INT_SUCCESS,"工程材料单查询成功",null);
            message.setData(pjMeterMaterialList);
            return message;
        } catch (Exception e) {
            logger.error("工程材料单查询失败",e);
        }
        return MessageBean.create(Constant.MESSAGE_INT_FAIL,"工程材料单查询失败",null);
    }
}
